//
//  DJMyFeedBackVC.m
//  daojiVideo
//
//  Created by tikeios_002 on 2024/6/7.
//

#import "DJMyFeedBackVC.h"
#import "HXPhotoView.h"
#import "UITextView+Placeholder.h"
#import "NSArray+HXExtension.h"
#import "QYDetailViewController.h"
#import "O2ODetailController.h"
#import "CSJADLoading.h"
#import "DJMyFeedBackHuifuVC.h"
@interface DJMyFeedBackVC ()<UITextViewDelegate,HXPhotoViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UILabel *textNumber;
@property (weak, nonatomic) IBOutlet YBTextFild *textPhone;
@property (weak, nonatomic) IBOutlet HXPhotoView *imageBgView;
@property (weak, nonatomic) IBOutlet UILabel *tip1;
@property (weak, nonatomic) IBOutlet UILabel *tip2;
@property (weak, nonatomic) IBOutlet UILabel *tip3;
@property (weak, nonatomic) IBOutlet UILabel *tip4;
@property (weak, nonatomic) IBOutlet UIButton *saveButton;
@property (weak, nonatomic) IBOutlet UIView *adView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *adHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageBgHeigh;

@property (strong, nonatomic)UIView * ding;

@end

@implementation DJMyFeedBackVC
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if([[QZUserInfoModel share].feedbackTotal intValue] > 0){
        _ding.hidden = NO;
    }else{
        _ding.hidden = YES;
    }
}
-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"意见反馈";
    
    
    
    self.tip1.text = @"请输入相关问题和意见";
    self.tip2.text = @"联系方式";
    self.tip3.text = @"反馈图片";
    self.tip4.text = @"(选填，提供问题截图)";
    [self.saveButton setTitle:@"提 交" forState:UIControlStateNormal];
    
    self.textView.delegate = self;
    self.textView.tintColor = MainColor;
    self.textView.placeholderColor = COLOR_ALPH(255, 255, 255, 0.82);
    self.textView.placeholder = @"请详细描述你的意见或遇到的问题，感谢你的支持";
    self.textPhone.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入你的联系方式" attributes:@{NSForegroundColorAttributeName:COLOR_ALPH(255, 255, 255, 0.82),NSFontAttributeName:[UIFont systemFontOfSize:14]}];
    self.textPhone.formaterType = YBAFormatterTextFieldFormatterTypePhone;
    
    self.imageBgHeigh.constant = (KScreen_W-38)/3;
    self.textView.delegate = self;
    self.imageBgView.delegate = self;
    self.imageBgView.lineCount = 3;
    self.imageBgView.manager.configuration.photoMaxNum = 3;
    self.imageBgView.manager.configuration.deleteTemporaryPhoto = NO;
    self.imageBgView.manager.configuration.lookLivePhoto = NO;
    self.imageBgView.manager.configuration.hideOriginalBtn = YES;
    self.imageBgView.manager.configuration.cameraCellShowPreview = NO;
    self.imageBgView.manager.configuration.photoCanEdit = NO;
    self.imageBgView.manager.configuration.themeColor = subviewback_black;
    self.imageBgView.manager.configuration.openCamera = YES;
    self.imageBgView.spacing = 4;
    self.imageBgView.addImageName = @"ico_feedback_add";
    self.imageBgView.clipsToBounds = YES;
    self.imageBgView.deleteImageName = @"ico_textfild_close";
    self.imageBgView.isDeleteTop = YES;
    self.imageBgView.addDarkImageName = @"ico_feedback_add";
    self.imageBgView.isLayerNot = YES;
    self.imageBgView.cellCornerRadius = 8;
    
    UIView * huifuBg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 88, 34)];
    
    UIButton * huifu = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 88, 34)];
    huifu.backgroundColor = subviewback_black;
    [huifu setTitle:@"反馈回复" forState:UIControlStateNormal];
    [huifu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    huifu.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    huifu.layer.cornerRadius = 5;
    [huifu addTarget:self action:@selector(huifuClick) forControlEvents:UIControlEventTouchUpInside];
    [huifuBg addSubview:huifu];
    
    _ding = [[UIView alloc]initWithFrame:CGRectMake(69, 2, 8, 8)];
    _ding.backgroundColor = [UIColor redColor];
    _ding.layer.cornerRadius = 4;
    _ding.clipsToBounds = YES;
    [huifuBg addSubview:_ding];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:huifuBg];
    
    
    
    UIView * QZTestTo6 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    QZTestTo6.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:QZTestTo6];
    UILabel * QZTestTo7 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger  QZTestTo8 = arc4random_uniform(20);
    NSLog(@"随机数：%ld", (long) QZTestTo8);
    QZTestTo7.text = [NSString stringWithFormat:@"%ld",(long)QZTestTo8];
    [QZTestTo6 addSubview:QZTestTo7];
    
    UIButton * QZTestTo12 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    NSString * QZTestTo13 = @"agadsgads";
    [QZTestTo12 setTitle:QZTestTo13 forState:UIControlStateNormal];
    
    UILabel * keyLabel = [[UILabel alloc] init];
    keyLabel.textColor = [UIColor grayColor];
    keyLabel.text = @"key";
    keyLabel.textAlignment = NSTextAlignmentCenter;
       UILabel * oldshowSSSSTip1 = [[UILabel alloc]init];
    oldshowSSSSTip1.clipsToBounds = YES;
    oldshowSSSSTip1.text = @"kass显示区";
    oldshowSSSSTip1.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip1.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip1.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip1.hidden = YES;
    [self.view addSubview:oldshowSSSSTip1];
    [self.view addSubview:keyLabel];
    
    UILabel * valueLabel = [[UILabel alloc] init];
    valueLabel.textColor = [UIColor grayColor];
    valueLabel.text = @"value";
    valueLabel.textAlignment = NSTextAlignmentCenter;
       UILabel * oldshowSSSSTip2 = [[UILabel alloc]init];
    oldshowSSSSTip2.clipsToBounds = YES;
    oldshowSSSSTip2.text = @"kass显示区";
    oldshowSSSSTip2.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip2.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip2.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip2.hidden = YES;
    [self.view addSubview:oldshowSSSSTip2];
    [self.view addSubview:valueLabel];
    
    UITextView * keyTextView1 = [[UITextView alloc] init];
    keyTextView1.backgroundColor = [UIColor whiteColor];
    keyTextView1.font = [UIFont systemFontOfSize:17];
    keyTextView1.layer.borderColor = [UIColor grayColor].CGColor;
    keyTextView1.layer.borderWidth = 1.0f;
    keyTextView1.layer.cornerRadius = 6.0f;
       UILabel * oldshowSSSSTip3 = [[UILabel alloc]init];
    oldshowSSSSTip3.clipsToBounds = YES;
    oldshowSSSSTip3.text = @"kass显示区";
    oldshowSSSSTip3.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip3.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip3.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip3.hidden = YES;
    [self.view addSubview:oldshowSSSSTip3];
    [self.view addSubview:keyTextView1];
    
    UITextView * valueTextView1 = [[UITextView alloc] init];
    valueTextView1.backgroundColor = [UIColor whiteColor];
    valueTextView1.font = [UIFont systemFontOfSize:17];
    valueTextView1.layer.borderColor = [UIColor grayColor].CGColor;
    valueTextView1.layer.borderWidth = 1.0f;
    valueTextView1.layer.cornerRadius = 6.0f;
    [self.view addSubview:valueTextView1];
    
    UITextView * keyTextView2 = [[UITextView alloc] init];
    keyTextView2.backgroundColor = [UIColor whiteColor];
    keyTextView2.font = [UIFont systemFontOfSize:17];
    keyTextView2.layer.borderColor = [UIColor grayColor].CGColor;
    keyTextView2.layer.borderWidth = 1.0f;
    keyTextView2.layer.cornerRadius = 6.0f;
       UILabel * oldshowSSSSTip4 = [[UILabel alloc]init];
    oldshowSSSSTip4.clipsToBounds = YES;
    oldshowSSSSTip4.text = @"kass显示区";
    oldshowSSSSTip4.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip4.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip4.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip4.hidden = YES;
    [self.view addSubview:oldshowSSSSTip4];
    [self.view addSubview:keyTextView2];
    KWeakSelf
    [CSJADLoading share].BannerAdsLoadFish = ^(id  _Nullable bannerView) {
        if(weakSelf.adView && bannerView != nil){
            [weakSelf.adView addSubview:bannerView];
            weakSelf.adHeight.constant = 45;
            [bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(weakSelf.adView);
            }];
            [UIView animateWithDuration:0.3 animations:^{
                [weakSelf.view layoutIfNeeded];
            }];
        }
        
    };
    [CSJADLoading ADBannerAdRequest:self];
}
- (void)huifuClick{
    DJMyFeedBackHuifuVC * vc = [[DJMyFeedBackHuifuVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)saveClick:(id)sender {
    [SVProgressHUDTool showWithStatus:nil];
    KWeakSelf
    if(self.imageBgView.manager.afterSelectedPhotoArray.count > 0){
        [self.imageBgView.manager.afterSelectedPhotoArray hx_requestImageWithOriginal:NO completion:^(NSArray<UIImage *> * _Nullable imageArray, NSArray<HXPhotoModel *> * _Nullable errorArray) {
            if(!imageArray.count){
                [SVProgressHUDTool dismiss];
                [YBMsgPop showPop:NSLocalizedString(@"错误", nil)];
                return;
            }
            [weakSelf uploadFeedBackRequest:imageArray];
        }];
    }
    else{
        [weakSelf uploadFeedBackRequest:nil];
    }
}
- (void)uploadFeedBackRequest:(NSArray *)imageArr{
    KWeakSelf
    KMutableDic(sendDic)
    sendDic[@"content"] = self.textView.text;
    sendDic[@"account"] = self.textPhone.text;
    [YBNetBase feedBackAddRequest:sendDic images:imageArr successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            [weakSelf.navigationController popViewControllerAnimated:YES];
            [YBMsgPop showPop:@"意见反馈提交成功，我们将认真查看你的意见反馈，请注意平台回复"];
        } else{
            [YBMsgPop showPop:msg];
        }
    }];
}
#pragma mark -UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView{
    if (textView.markedTextRange == nil) {
        textView.text = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
        if (textView.text.length > 300) {
            textView.text = [textView.text substringToIndex:300];
        }
        
        self.textNumber.text = [NSString stringWithFormat:@"%li/%d",textView.text.length,300];
    }
}
- (IBAction)onTap1:(UIGestureRecognizer *)recognizer {
    QYDetailViewController *vc = [[QYDetailViewController alloc] init];
    vc.index = 1;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)onTap2:(UIGestureRecognizer *)recognizer {
    QYDetailViewController *vc = [[QYDetailViewController alloc] init];
    vc.index = 2;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)onTap3:(UIGestureRecognizer *)recognizer {
    QYDetailViewController *vc = [[QYDetailViewController alloc] init];
    vc.index = 3;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)onTap4:(UIGestureRecognizer *)recognizer {
    QYDetailViewController *vc = [[QYDetailViewController alloc] init];
    vc.index = 4;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)showToast:(NSString *)toast {
    UIViewController *topVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    if (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
    }

}

- (UIImage *)getImageInBundle:(NSString *)imageName {
    NSString *name = [@"QYCustomResource.bundle" stringByAppendingPathComponent:imageName];
    UIImage *image = [UIImage imageNamed:name];
    if (!image) {
        name = [@"QYResource.bundle" stringByAppendingPathComponent:imageName];
        image = [UIImage imageNamed:name];
    }
    return image;
}
@end
